<template>
	<el-container>
		<el-header style="font-size: 16px;font-weight: 600">档案参数设置</el-header>
		<el-main class="nopadding">
			<el-main>
				<el-form>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="借阅人员权限" label-width="150px">
								<select-user-dialog v-model:accountId="form.borrowingUserRole" :mode="true"/>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">设置档案借阅人员范围。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="借阅部门权限" label-width="150px">
								<select-dept-dialog v-model:deptId="form.borrowingDeptRole" :mode="true"/>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">设置档案借阅部门范围。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="借阅职务权限" label-width="150px">
								<select-user-level-dialog v-model:levelId="form.borrowingLevelRole" :mode="true"/>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">设置档案职务部门范围。</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="编号规则" label-width="150px">
								<el-select v-model="form.codeRuleId" clearable style="width: 100%">
									<el-option v-for="item in ruleOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">档案归档时自动生成档案编号规则</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="借阅流程" label-width="150px">
								<el-select v-model="form.borrowingFlowId" clearable style="width: 100%">
									<el-option v-for="item in flowOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">档案借阅流程关联</span>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="字段映射" label-width="150px">
								<el-input v-model="form.borrowingDataMap" maxlength="380" clearable type="textarea"></el-input>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">档案流程字段映射,如:(业务字段名称1:流程字段1,业务字段名称2:流程字段2)</span>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</el-main>
		</el-main>
		<el-footer class="footer">
			<el-button type="primary" @click="setSysConfig">设置</el-button>
		</el-footer>
	</el-container>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog.vue";
import selectDeptDialog from "@/views/module/selectDeptDialog.vue";
import selectUserLevelDialog from "@/views/module/selectUserLevelDialog.vue";

export default {
	name: 'config',
	components: {selectUserLevelDialog, selectDeptDialog, selectUserDialog},
	data() {
		return {
			ruleOptions:[],
			flowOptions:[],
			form: {
				borrowingUserRole:'',
				borrowingDeptRole: '',
				borrowingLevelRole: '',
				borrowingFlowId: '',
				borrowingDataMap: '',
				codeRuleId:'',
			},
		}
	},
	mounted() {
		this.getBpmFlowListForSelect();
		this.getArchivesConfig();
		this.getSysCodeRuleListForSelect();
	},
	methods: {
		async getBpmFlowListForSelect()
		{
			var res = await this.$API.bpm.bpmFlow.getBpmFlowListForSelect.get({model:'0'});
			if(res.code == 200){
				this.flowOptions = res.data;
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getSysCodeRuleListForSelect()
		{
			var res = await this.$API.system.sysCodeRule.getSysCodeRuleListForSelect.get();
			if(res.code == 200){
				this.ruleOptions = res.data;
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async setSysConfig() {
			var res = await this.$API.archives.archivesConfig.setArchivesConfig.post(this.form);
			if (res.code == 200) {
				this.$message.success(res.message)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getArchivesConfig() {
			var res = await this.$API.archives.archivesConfig.getArchivesConfig.get();
			if (res.code == 200) {
				this.form = res.data;
				this.form.bpanCode='';
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>

<style scoped>
.footer {
	text-align: center;
}
</style>
